home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / callback.001 / callback~ / callback / lib / process / modemkill.c < prev    next >
C/C++ Source or Header  |  1996-07-23  |  1KB  |  57 lines

  1.  
  2. #include "process.p"
  3.  
  4. int modemkill(char *processline)
  5. {                                    
  6.     int 
  7.         kills,
  8.         pid;
  9.     char
  10.         *cp,
  11.         *modem,
  12.         *line;
  13.                
  14.     modem = getmodembase();
  15.  
  16.     if ((cp = strrchr(modem, '/')))             /* look for the last part of */
  17.         modem = cp + 1;                         /* the modembase: beyond /   */
  18.  
  19.     log(log_max, "process: '%s'", processline);
  20.     if (!strstr(processline, modem))
  21.     {
  22.         log(log_max, "no modem process on this line");
  23.         return (0);                             /* no modem process */
  24.     }
  25.               
  26.     kills = 0;
  27.     reset_active_tty();
  28.     while ((line = get_active_tty()))           /* check actives */
  29.     {
  30.         if (strstr(processline, line))          /* modembase and line found */
  31.         {
  32.         if (sscanf(processline, " %d", &pid) != 1)
  33.             log(log_off, "Can't find PID in ps-output '%s'", processline);
  34.  
  35.         else if (kill(pid, SIGTERM))
  36.             log(log_off, "Can't 'kill(%d, SIGTERM)' for process '%s'", 
  37.              pid, processline);
  38.             
  39.             else
  40.             {
  41.                 assign_filenames(line);
  42.                 log(log_on, "SIGTERM received by %s", getfile(the_modemfile));
  43.                 kills++;
  44.             }
  45.     }
  46.         else
  47.             log(log_max, "no modem process for line '%s'", line);
  48.     }
  49.  
  50.     if (kills)
  51.         return (kills);
  52.  
  53.     log(log_on, "Skipped modem-process: '%s'", processline);
  54.     return (0);
  55. }
  56.     
  57.